package com.project_doctor.mapper;

import com.project_doctor.pojo.AnnouncementReceiver;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.project_doctor.pojo.Doctor;
import com.project_doctor.pojo.SystemAnnouncement;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
/**
* @author 龙龙与贝儿
* @description 针对表【t_announcement_receiver】的数据库操作Mapper
* @createDate 2025-06-05 15:54:28
* @Entity com.project_doctor.pojo.AnnouncementReceiver
*/
public interface AnnouncementReceiverMapper extends BaseMapper<AnnouncementReceiver> {
    @Select("SELECT * FROM t_announcement_receiver WHERE announcement_id = #{announcementId}")
    List<AnnouncementReceiver> selectReceiversByAnnouncementId(@Param("announcementId") Long announcementId);


    @Select("SELECT " +
            "r.id, " +
            "r.announcement_id, " +
            "r.receiver_id, " +
            "r.sender_id, " +
            "r.read_status, " +
            "a.message_title, " +
            "a.publish_time, " +
            "d.name AS sender_name " +
            "FROM t_announcement_receiver r " +
            "LEFT JOIN t_system_announcement a ON r.announcement_id = a.id " +
            "LEFT JOIN t_doctor d ON r.sender_id = d.id " +
            "WHERE r.receiver_id = #{receiverId}")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "announcementId", column = "announcement_id"),
            @Result(property = "receiverId", column = "receiver_id"),
            @Result(property = "senderId", column = "sender_id"),
            @Result(property = "readStatus", column = "read_status"),

            @Result(property = "systemAnnouncement.messageTitle", column = "message_title"),
            @Result(property = "systemAnnouncement.publishTime", column = "publish_time"),

            @Result(property = "sender.name", column = "sender_name"),
    })
    List<AnnouncementReceiver> selectListWithAnnSender(Long receiverId);
}




